package dao

import (
	"git.supremind.info/product/box/vehicle/internal/util"
	"time"
)

type SchemaHistory struct {
	ID          uint      `gorm:"primary_key" json:"id"`
	Version     string    `json:"version"`
	Description string    `json:"description"`
	Script      string    `json:"script"`
	CreateTime  time.Time `json:"create_time"`
	UpdateTime  time.Time `json:"update_time"`
}

func (t *SchemaHistory) TableName() string {
	return "schema_history"
}

func (t *SchemaHistory) Insert() (uint, error) {
	if err := DB.Create(t).Error; err != nil {
		util.Log().Error("无法插入数据库记录, %s", err)
		return 0, err
	}
	return t.ID, nil
}

func (t *SchemaHistory) Update(props map[string]interface{}) error {
	return DB.Model(t).Updates(props).Error
}

func (t *SchemaHistory) Delete() error {
	return DB.Model(t).Delete(t).Error
}
